package org.example.spring.annoTx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;

//账户操作持久层
//技术方案：jdbcTemplate
@Repository("accountDAO")
public class AccountDAO extends JdbcDaoSupport {

	@Autowired // 被spring自动调用
	public void setSuperDataSourceMethod(DataSource dataSource){
		System.out.println("AccountDAO类中的setSuperDataSourceMethod方法执行了");
		super.setDataSource(dataSource); // 将dataSource传递给父类
	}

	//转入
	public void in(String name,Double money){
		String sql="update t_account set money = money+ ? where name = ?";
		super.getJdbcTemplate().update(sql, money,name);
	}
	
	//转出
	public void out(String name,Double money){
		String sql="update t_account set money = money- ? where name = ?";
		super.getJdbcTemplate().update(sql, money,name);
	}


}
